var CodeInfoDlg = {

	CodeInfoData: {},
	deptZtree: null,
	pNameZtree: null,
	validateFields: {
		id_card: {
			validators: {
				notEmpty: {
					message: '身份证不能为空'
	 			},
				regexp: {
					regexp: /^\d{13}$/,
					message: '身份证格式错误'
	 			},
	 		}
	 	},
		// id_card_upside_no: {
		// 	validators: {
		// 		regexp: {
		// 			regexp: /^[a-zA-Z0-9]{4}-\d{1}\.\d{1}-\d{2}-[a-zA-Z0-9]{4}$/,
		// 			message: '身份证反面数字1格式错误'
	 	// 		},
	 	// 	}
	 	// },
		// id_card_upside_two: {
		// 	validators: {
		// 		regexp: {
		// 			regexp: /^[a-zA-Z0-9]{3}-\d{7}-\d{2}$/,
		// 			message: '身份证反面数字2格式错误'
	 	// 		},
	 	// 	}
	 	// },

		// idcardimg: {
		// 	validators: {
		// 		notEmpty: {
		// 			message: '身份证图片不能为空'
		// 		},
		// 	}
		// },
		// idcardimgel: {
		// 	validators: {
		// 		notEmpty: {
		// 			message: '英文身份证图片不能为空'
		// 		},
		// 	}
		// },
		// bankimg: {
		// 	validators: {
		// 		notEmpty: {
		// 			message: '银行本图片不能为空'
		// 		},
		// 	}
		// },
		// wjbhzimg: {
		// 	validators: {
		// 		notEmpty: {
		// 			message: '外交部护照不能为空'
		// 		},
		// 	}
		// },
		director_id: {
			validators: {
				notEmpty: {
					message: '承办人不能为空'
				},
			}
		},
		// translater_id: {
		// 	validators: {
		// 		notEmpty: {
		// 			message: '翻译不能为空'
		// 		},
		// 	}
		// },
	 }
}


CodeInfoDlg.clearData = function () {
	 this.CodeInfoData = {};
};


CodeInfoDlg.set = function (key, value) {
	 this.CodeInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
	 return this;
};


CodeInfoDlg.get = function (key) {
	 return $("#" + key).val();
};


CodeInfoDlg.close = function () {
	 var index = parent.layer.getFrameIndex(window.name);
	 parent.layer.close(index);
};

CodeInfoDlg.collectData = function () {
	this.set('id').set('id_card').set('idcardimg').set('idcardimgel').set('bankimg').set('wjbhzimg').
	set('first_name').set('last_name').set('birth_day').set('religion').set('addr').set('translater_id').
	set('expiry_date').set('id_card_upside_no').set('id_card_upside_two').set('work_year').set('work_month').set('ggz').
	set('mobile').set('introducer').set('introducer_id').set('director_id').set('translater_id').set('director').set('tzsslbh').set('work_times');
	let id_card_upside_no = this.get('id_card_upside_no').toLocaleUpperCase();
	this.set('id_card_upside_no',id_card_upside_no);
	let id_card_upside_two = this.get('id_card_upside_two').toLocaleUpperCase();
	this.set('id_card_upside_two',id_card_upside_two);
};


CodeInfoDlg.add = function () {
	this.clearData();
	this.collectData();
	if (!this.validate()) {
		return;
	}
	var is_hz_dg = $("input[name = 'is_hz_dg']:checked").val();
	var is_yhb_dg = $("input[name = 'is_yhb_dg']:checked").val();
	var is_rename = $("input[name = 'is_rename']:checked").val();
	var is_introducer = $("input[name = 'is_introducer']:checked").val();
	var is_jlzdg = $("input[name = 'is_jlzdg']:checked").val();
	//var introducer_id = $('#introducer_id option:selected') .val();

	var tip = '添加';
	if(is_introducer==1 && introducer_id==0) {
		Feng.error(tip + "请选择介绍人！" + "！");
		return;
	}
	var ajax = new $ax(Feng.ctxPath + "/Record.Customer/add", function (data) {
		if ('00' === data.status) {
			Feng.success(tip + "成功" );
			window.parent.CodeGoods.table.refresh();
			CodeInfoDlg.close();
		} else {
			Feng.error(tip + "失败！" + data.msg + "！");
	 	}
	}, function (data) {
		Feng.error("操作失败!" + data.responseJSON.message + "!");
	});

	ajax.set('is_rename',is_rename);
	ajax.set('is_hz_dg',is_hz_dg);
	ajax.set('is_yhb_dg',is_yhb_dg);
	ajax.set('is_introducer',is_introducer);
	ajax.set('is_jlzdg',is_jlzdg);
	//ajax.set('introducer_id',introducer_id);
	ajax.set(this.CodeInfoData);
	ajax.start();
};

CodeInfoDlg.update = function () {
	this.clearData();
	this.collectData();
	if (!this.validate()) {
		return;
	}
	var is_hz_dg = $("input[name = 'is_hz_dg']:checked").val();
	var is_yhb_dg = $("input[name = 'is_yhb_dg']:checked").val();
	var is_rename = $("input[name = 'is_rename']:checked").val();
	var is_introducer = $("input[name = 'is_introducer']:checked").val();
	var is_jlzdg = $("input[name = 'is_jlzdg']:checked").val();
	//var introducer_id = $('#introducer_id option:selected') .val();

	var tip = '修改';
	if(is_introducer==1 && introducer_id==0) {
		Feng.error(tip + "请选择介绍人！" + "！");
		return;
	}
	var ajax = new $ax(Feng.ctxPath + "/Record.Customer/update", function (data) {
		if ('00' === data.status) {
			Feng.success(tip + "成功" );
			window.parent.CodeGoods.table.refresh();
			CodeInfoDlg.close();
		} else {
			Feng.error(tip + "失败！" + data.msg + "！");
		}
	}, function (data) {
		Feng.error("操作失败!" + data.responseJSON.message + "!");
	});

	ajax.set('is_rename',is_rename);
	ajax.set('is_hz_dg',is_hz_dg);
	ajax.set('is_yhb_dg',is_yhb_dg);
	ajax.set('is_introducer',is_introducer);
	ajax.set('is_jlzdg',is_jlzdg);
	//ajax.set('introducer_id',introducer_id);
	ajax.set(this.CodeInfoData);

	ajax.start();
};
CodeInfoDlg.status = function () {
	this.clearData();

	var tip = '修改';
	var ajax = new $ax(Feng.ctxPath + "/Record.Customer/status", function (data) {
		if ('00' === data.status) {
			Feng.success(tip + "成功" );
			window.parent.CodeGoods.table.refresh();
			CodeInfoDlg.close();
		} else {
			Feng.error(tip + "失败！" + data.msg + "！");
		}
	}, function (data) {
		Feng.error("操作失败!" + data.responseJSON.message + "!");
	});

	// ajax.set('id_card_fee');
	// ajax.set('pass_port_fee',is_hz_dg);
	this.set('id').set('id_card_fee').set('pass_port_fee');
	ajax.set('status',1);
	ajax.set(this.CodeInfoData);

	ajax.start();
};

CodeInfoDlg.statusOne = function () {
	this.clearData();
	var tip = '修改';
	var ajax = new $ax(Feng.ctxPath + "/stepone/status", function (data) {
		if ('00' === data.status) {
			Feng.success(tip + "成功" );
			window.parent.CodeGoods.table.refresh();
			CodeInfoDlg.close();
		} else {
			Feng.error(tip + "失败！" + data.msg + "！");
		}
	}, function (data) {
		Feng.error("操作失败!" + data.responseJSON.message + "!");
	});

	// ajax.set('id_card_fee');
	// ajax.set('pass_port_fee',is_hz_dg);
	this.set('id').set('id_card_certification_fee').set('pass_port_certification_fee');
	ajax.set('status',2);
	ajax.set(this.CodeInfoData);

	ajax.start();
};

CodeInfoDlg.statusThree = function () {
	this.clearData();
	var tip = '修改';
	var ajax = new $ax(Feng.ctxPath + "/stepthree/status", function (data) {
		if ('00' === data.status) {
			Feng.success(tip + "成功" );
			window.parent.CodeGoods.table.refresh();
			CodeInfoDlg.close();
		} else {
			Feng.error(tip + "失败！" + data.msg + "！");
		}
	}, function (data) {
		Feng.error("操作失败!" + data.responseJSON.message + "!");
	});

	// ajax.set('id_card_fee');
	// ajax.set('pass_port_fee',is_hz_dg);
	this.set('id').set('id_card_lsg_fee').set('pass_port_lsg_fee').set('ggz');
	ajax.set('status',4);
	ajax.set(this.CodeInfoData);
	ajax.start();
};

CodeInfoDlg.setFy = function () {
	this.clearData();
	var fy_id = $("input[name = 'translater_id']:checked").val();
	var tip = '修改';
	var ajax = new $ax(Feng.ctxPath + "/stepthree/zhipai", function (data) {
		if ('00' === data.status) {
			Feng.success(tip + "成功" );
			window.parent.CodeGoods.table.refresh();
			CodeInfoDlg.close();
		} else {
			Feng.error(tip + "失败！" + data.msg + "！");
		}
	}, function (data) {
		Feng.error("操作失败!" + data.responseJSON.message + "!");
	});

	this.set('id');
	ajax.set('translater_id',fy_id);
	ajax.set(this.CodeInfoData);
	ajax.start();
};

CodeInfoDlg.income = function () {
	this.clearData();
	var tip = '修改';
	var ajax = new $ax(Feng.ctxPath + "/stepfive/status", function (data) {
		if ('00' === data.status) {
			Feng.success(tip + "成功" );
			window.parent.CodeGoods.table.refresh();
			CodeInfoDlg.close();
		} else {
			Feng.error(tip + "失败！" + data.msg + "！");
		}
	}, function (data) {
		Feng.error("操作失败!" + data.responseJSON.message + "!");
	});

	// ajax.set('id_card_fee');
	// ajax.set('pass_port_fee',is_hz_dg);
	this.set('id').set('lbj_fee');
	ajax.set('status',7);
	ajax.set(this.CodeInfoData);
	ajax.start();
};


CodeInfoDlg.validate = function () {
	$('#CodeInfoForm').data("bootstrapValidator").resetForm();
	$('#CodeInfoForm').bootstrapValidator('validate');
	return $("#CodeInfoForm").data('bootstrapValidator').isValid();
};


$(function () {
	Feng.initValidator("CodeInfoForm", CodeInfoDlg.validateFields);
});


